better form behavior and some refactoring