all edge case considered and fixed