organize js code better