merged code, tested and working :-)