functions and some tweaking