Rewrote constructor to fix stack corruption.