some refactoring and bugfixing with forms