bugfix from tspurway's modification