Performance improvements and added comments to all current functions.