various code refactor