initializing using beej's example code