Added jsDocs, general code improvements.