cleaned up some code, added better failing mechanism