Cleaned up code, added further optimization.
what a crap last commit. Error checks...