Added contrast function and cleaned code