updated by Béla for better Android performance