Rewritten calculator with validations and structure