Finished the core implementation. Still needs testing