fixed bugs in roll function