Removed debug code, added an error catch