cleaned up javascript code