some refactoring and some bug fixes, save before getting rid of data types