bugfix for keyboard#replace() and cleanup