Still works, about to split into several files