draft 2

made javascript more functional