Refactored a bit; this is buildable