Full working not beautiful version, includes writing