Some simple boyscouting

Cleaned up unused code, redundant casts and simplified code. Nothing special.