heavily modified main don't assume it makes sense yet