bug fixes, initial working version