first pass, not very tested yet, and pretty hacky but still cleaner