Cleaned up code and simplified asserts.