Ported a few improvements from tapkee