Refactored and ported to ST3