messy but working function calls