Type propogation

Add type casting in most places.