reformat GINORMOUS sql query and make it more readable
add business logic for transfer function keys
Merge branch '5256_func_key_transfer_2'