Fixed some unexpected behaviour
Added new functions, plus some minor fixes