Fixed numerous memory leaks and added new option for specifying icon