Streamlined & fixed code