Metaprogramming (and borrowing code from the interwebs and ilude) for the win