some bug fixes and changes

it may be a mess to merge manually... u can try or just reclone