Added memory allocation and manual key setting