first batch of code refactor.