Fixed variable use and unnecessary casting