js code for day app tidied up into seperate functions