Fixed double parsing bug. Code cleanup