Basic idea works. Improvements will be made later