Various changes that make less assumptions about things

As a result the code is more robust, throws less errors and is usable in more situations