Assertion fixed
Better function code