Cleaned up code, comments. And refined the test file.