Some little bug fixes and added a bit of test code
More comments