Main functionality implemented, no testing yet.