Fixed references and other minor bugs