Addressed boundary case crash
Started work on optimisation