cleaning up javascript code