Adding tests ; fixing bugs