Refactor to more compact structure