Cleans up and merges #1090 (Thanks @AtoxIO)