Refactor

Manual merge of #248