added validation and moving some js into files