Added 'or replace' for better function updating, reordered funtions to work as found in file.