lots of bug fixes, missing functions