basic memory management and uart wait fix