Refined code

Refined the code, added boundary markers, removed some of the pointers