Cleanup of some code + notes on what is going on