fixed exception handling, doubled/halved array size when necessary