Move keys functions to own file