Catching more exceptions and some refactoring resolve #16