Issue 1315

Fixes #1315 once merged.

Joint effort by @ahmedbodi and @myrinx with some cleanup by myself. Thanks guys :)