Refactor kexp.rb