Fixed reference checking and also added inffered types