Fixed main logic. TODO - delete method