make function constant time
small fixes