Implementation of system calls, based on JamesM tutorial