Developing, optimising and refactoring scientific software