Factor bayeslr utility functions to separate file.