Helper functions and classes