optimise code, remove console logs and edit document ready function