Refactored for better error logging
Better logging, closes #3