Misc. functions for R