completed core logic