bug fixes to get it working