moved functional code to class and bugfixes
moved functional code to class and bugfixes