various fixes, feels ready to be merged