more code cleanup, fixed some sync issues