Fix write issues
bugfixes and static memory allocation