Adding Tests and refactoring structure