Improve functioning and optimise code