Helper functions for R