Make ctrl+y work and refactor code.