Many changes to better support functions