Code refactoring; better API