refactor beginning