plenty of changes to sync

repair bugs and add some lightweight functions