bug fixes and some tests, committing all changes before merging back to master