Added more logic
changed dup slightly