Updated error handling, added temp logging functions for debugging...