fixed refactor
upcast not working 100% of the time