Bug fixed and simplified (with commented old code)