refactored and fixed parser bug