Improve code add debug prints