Minor bug fixes

Fixed a few warnings and refactored some parts.