Updated with some suggestions from @johannesl. #5