Massive simplification and bugfixing