Some improvement to code and re-factored tests and created new ones