Partially correct code

Need to fix -1 and 1 cases