Completed main implementation and debugging