semaphore used to regulate access
moved to macros and added most routines