General style improvements. Changed type comparisons to isinstance.