added boundary handling and TODOS
added boundary handling and TODOS