Added some comments and improved logging system