code cleanup
couble fixes, also pending flag