Add references and perform general cleanup of code