adding (edited) code from Veeru