fixed bug, tested