added tests and better structure.