refactor into more readable chunks