Some comments and code made more functional in nature.