Cleaned up code, added exceptions to exceptional cases for eventual logging purposes.