Fix whitespaces parsing and add tests