Added locations, cleaned up exception handling code