Trying to fix 'null' cases and fixing some minor mistakes on debugs.
Cleaning and commenting the code