bug fixes to make it work