written function coding, bug fixes, added include guard