code cleanup, improved parser