Improved more comments. Made a few methods static for performance reasons. Set a few parameters as const.