added new test cases. refactor of factories. improve error handling.