More tidy up and optimization