fixing bugs with code

Adding monotonicity etc.