updated code ... still working condition