fixed bug in wtatage function implementation