further modularizes js code