Implement handling of brackets and refactor code so it accepts inputs with empty spaces between elements of the expression