wrote raw algorithm