Removed debug code
Added more checks
Removed debug code