Fixed bad definition for k, code needs cleanup