functions and bugfix