fixed some painful bugs