Fixed bad function implementation