key switching implemented but doesn't work. not sure why.
careful, very ugly code! use at own risk!