fixed bug at the end