fixed all the hanging issues
implemented buffer