First version without much refactor