code refactor to include methods in methods