Refactor fixes
cleanup
shared functions