Included main logic. Not yet working fully.