Implement snapping to previewed item
Refactor get rid of unused vars
Refactor as a module
Refactor. Separate library from usage code.