Initial code with the logic