Refactored using substr() and therefore compatible to C