debugged parsing algorithm, cleaned up code style. It needs to be optimized