Some refactoring to make it ready fro running