bugs fixes, refactors