Fixed bug with stack corruption