Bugfix

Fixed a couple of bugs with potential undefined cases and class errors.