Moved all magic to a proper class, fixed issue #1