some function refactoring and... stuff