refactoring and changing write testcases

Signed-off-by: Markus Jura <markus.jura@googlemail.com>