TODO: Tests and bugfixing