more refactoring, clean up javascript