Changed the code for more debugging and clarity