First beta version, after some refactoring. Main functionality seems to work