Refactored MiscFunctions and cleaned up certain comments