Clean up imports

Signed-off-by: Jakob Bornecrantz <wallbraker@gmail.com>
Cactch exceptions and return error codes

Signed-off-by: Jakob Bornecrantz <wallbraker@gmail.com>