All functions for HW5 working