Fixed bug in show() and createAndShow() methods and optimized code