Slight refactor + other bug fixes