Working on api and tidying up js