Clean up and fix bug related to parent function