Refactoring. Now there is no segfault :-)