Removed some warnings, code cleanup and added tons of comments