Main refactored, cleaner but still does not work.