Code cleanup, bit of refactoring