modified some lame code, replaced by code provided in GISC book