re-organizing some functions