renamed functions according to standard. Also added in free statements so that memory would be correctly freed