refactors some code smells (javascript)