cleaned up parsing code