seperated up functions.c
improved xoffsetfactor re-alignment code