update with listeners, improved code