final bug fix (tested and working)