almost done with the core logic