some helper functions and polish