Basic implementation, needs major refactoring