code improvements and better type casting