Refactor a bit
Parse to internal format