Initial working version, still needs work