Various fixes, moved usings inside namespace, improved error handling