Added worker test
Bug fixes and refactoring