util file moved into a header file and bugs fixed