Refactor and improved abstract syntax implementation