Add basic functionality and refactoring