Code clean up and correct referencing