refac, bugfixes