Added working mod function